/*
 * Created on 2005/05/01
 * Author aki@www.xucker.jpn.org
 * License Apache2.0 or Common Public License
 */
package jp.sourceforge.akjrcp.audiotools;

import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;

import java.awt.image.BufferedImage;

/**
 * 
 *
 */
public class BufferedImagePainter {
private ProgressMonitor monitor;
public static final int DEFAULT_PERCHECK=50;
private int percheck=DEFAULT_PERCHECK;

public int getMaxProgress(int y){
    return y/percheck;
}
public ProgressMonitor getMonitor() {
    return monitor;
}
public void setMonitor(ProgressMonitor monitor) {
    this.monitor = monitor;
}
public int getPercheck() {
    return percheck;
}
public void setPercheck(int percheck) {
    this.percheck = percheck;
}
//BufferedImage is ARGB;
public  void drawAtBufferedImage(BufferedImage bimg,Image image,int x,int y){
    ImageData data=image.getImageData();
   
    int at=0;
    
       
        for(int j=0;j<image.getBounds().height;j++){
            for(int i=0;i<image.getBounds().width;i++){
            
            int r=0xff & data.data[at+2];
            int g=0xff & data.data[at+1];
            
            
            
            int b=0xff & data.data[at];
           
            bimg.setRGB(i+x,j+y,0xFF<<24 | r<<16 | g<<8 | b<<0);
            at+=4;
        }
        
        if(monitor!=null && j%percheck==0){
            if(monitor.isCanceled()){
                return;
            }
            monitor.worked(percheck);
        	}
        }
    
}

}
